package io.gitee.kenewstar.dbmq.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.locks.LockSupport;

/**
 * @author kenewstar
 */
public abstract class CommonThread extends Thread {

    protected static final Logger LOGGER = LoggerFactory.getLogger(CommonThread.class);

    protected volatile ThreadStatus threadStatus = ThreadStatus.NEW;

    public boolean isRunning() {
        return ThreadStatus.RUNNING.equals(threadStatus);
    }

    public boolean isNew() {
        return ThreadStatus.NEW.equals(threadStatus);
    }

    public boolean isWaiting() {
        return ThreadStatus.WAITING.equals(threadStatus);
    }

    public void close() {
        this.threadStatus = ThreadStatus.DEAD;
        LockSupport.unpark(this);
    }


}
